Skip to content

Commit 31cd18a

Browse files
committed
data migration to rename topic title
1 parent d64b11b commit 31cd18a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 4.2.21 on 2025-05-20 14:23
2+
3+
from django.db import migrations
4+
5+
6+
def update_topic_title(apps, schema_editor):
7+
Topic = apps.get_model("products", "Topic")
8+
9+
try:
10+
topic = Topic.objects.get(
11+
title="Cookies",
12+
is_archived=False,
13+
parent__title="Tracking protection",
14+
parent__is_archived=False,
15+
parent__parent__title="Privacy and security",
16+
parent__parent__is_archived=False,
17+
parent__parent__parent__isnull=True,
18+
)
19+
except Topic.DoesNotExist:
20+
print('The topic "Privacy and security > Tracking protection > Cookies" does not exist.')
21+
except Topic.MultipleObjectsReturned:
22+
print(
23+
'Multiple instances of the topic "Privacy and security > Tracking protection'
24+
' > Cookies" exist.'
25+
)
26+
else:
27+
topic.title = "Cookies as trackers"
28+
topic.save()
29+
print(
30+
'Successfully updated the title of the topic "Privacy and security > Tracking'
31+
' protection > Cookies" to "Cookies as trackers".'
32+
)
33+
34+
35+
class Migration(migrations.Migration):
36+
37+
dependencies = [
38+
("products", "0023_initial_topic_metadata"),
39+
]
40+
41+
operations = [
42+
migrations.RunPython(update_topic_title, migrations.RunPython.noop),
43+
]

0 commit comments

Comments
 (0)